package com.example.studentapp.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.studentapp.R;
import com.example.studentapp.beans.Course;
import com.example.studentapp.utils.CourseMsg;

import java.util.List;
import java.util.Random;

public class CourseListNowAdapter extends BaseAdapter {
    Context context;
    List<Course> list;
    int[] icons = {R.drawable.course_anim,R.drawable.course_auto,R.drawable.course_jsj,R.drawable.android};
    public CourseListNowAdapter(Context context, List<Course> list){
        this.context = context;
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.item_course_now,null);
        TextView item_name_nowTV = view.findViewById(R.id.item_name_nowTV);
        item_name_nowTV.setText(list.get(i).getName());
        TextView item_time_placeTV = view.findViewById(R.id.item_time_placeTV);
        item_time_placeTV.setText(CourseMsg.sectionTime(list.get(i).getSection()) + " " + list.get(i).getPlace());

        TextView item_tea_nowTV = view.findViewById(R.id.item_tea_nowTV);
        item_tea_nowTV.setText(list.get(i).getTeacher());
        ImageView iconIV = view.findViewById(R.id.iconIV);
        iconIV.setImageResource(icons[new Random().nextInt(icons.length)]);
        return view;
    }
}
